/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.santi.framework.util;

/**
 *
 * @author Prabhat
 */
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtil {
    // private static Logger log = Logger.getLogger(CompareUtil.class);

    public StringUtil() {
        super();
    }

    public static boolean isNullOrBlank(String str) {
        if (str == null
                || str.length() == 0
                || str.trim().length() == 0) {
            return true;
        } else {
            return false;
        }
    }

    /**
     * To check if for numeric validation
     *
     * @param String
     * @return boolean value
     */
    public static boolean validateNumber(String contractLength) {
        boolean nullFlag = false;
        nullFlag = isNullOrBlank(contractLength);
        if (!nullFlag) {
            String str = contractLength;
            //  log.debug("contractLength is::"+str);
            return str.matches("[\\d]+");
        } else {
            return nullFlag;
        }
    }

    /**
     * To check if for aplhanumeric validation
     *
     * @param String
     * @return boolean value
     */
    public static boolean validateAplhanumeric(String input) {
        //   log.debug("input is::"+input);
        boolean flag = false;
        char inputArray[] = input.toCharArray();
        if (!(isNullOrBlank(input))) {
            for (int i = 0; i < input.length(); i++) {
                char eachLetter = inputArray[i];
                String letter = Character.toString(eachLetter);
                Pattern pat = Pattern.compile("[a-zA-Z0-9]");
                Matcher matcher = pat.matcher(letter);
                flag = matcher.find();
                if (!flag) {
                    break;
                } else {
                    flag = true;
                }
            }
        }
        return flag;
    }
}
